<template>
  <template v-for="item in userMenus" :key="item.id">
    <template v-if="item.type === 1">
      <el-sub-menu :index="item.id + ''">
        <template #title>
          <el-icon v-if="item.icon">
            <component :is="item.icon"></component>
          </el-icon>
          <span>{{ item.name }}</span>
        </template>
        <menu-tree :user-menus="item.children"></menu-tree>
      </el-sub-menu>
    </template>
    <template v-else-if="item.type === 2">
      <el-menu-item :index="item.id + ''" @click="itemHandleClick(item)">
        <el-icon v-if="item.icon">
          <component :is="item.icon"></component>
        </el-icon>
        <span>{{ item.name }}</span>
      </el-menu-item>
    </template>
  </template>
</template>
<script setup lang="ts">
import { defineProps, PropType } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const props = defineProps({
  userMenus: {
    type: Array as PropType<any[]>
  }
})
const itemHandleClick = (item: any) => {
  router.push(item.url ?? '/notFound')
}
</script>
<style scoped lang="less">
.el-sub-menu {
  background-color: #001529 !important;

  // 二级菜单 ( 默认背景 )
  .el-menu-item {
    padding-left: 50px !important;
    background-color: #0c2135;
  }
}

// hover 高亮
.el-menu-item:hover {
  color: #fff !important; //
  background-color: #0c2135 !important;
}

.el-menu-item.is-active {
  color: #fff !important;
  background-color: #0a60bd !important;
}

.el-sub-menu :deep(.el-sub-menu__title):hover {
  background-color: #001529 !important;
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 100%;
  height: calc(100% - 48px);
}
</style>
